using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Quiki.ExpressionParsers
{
    public class WikiTemplateElement : WikiTextElement
    {
        public WikiTemplateElement()
            : base (WikiTextElementType.Template)
        {
            Terminal = true;
        }

        public WikiTemplateElement (string templateName, IEnumerable<string> templateParameters)
            : this()
        {
            TemplateName = templateName;
            TemplateParameters = new List<string>(templateParameters);
        }

        public WikiTemplateElement (string templateName, string templateParameter)
            : this ()
        {
            TemplateName = templateName;
            TemplateParameters = new List<string> { templateParameter };
        }

        public string TemplateName
        {
            get { return (string) Properties["name"]; }
            set { Properties["name"] = value; }
        }

        [SuppressMessage ("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public IList<string> TemplateParameters
        {
            get { return (IList<string>) Properties["parameters"]; }
            set { Properties["parameters"] = value; }
        }

        public string GetTemplateParameter(int index)
        {
            return TemplateParameters[index];
        }
    }
}